package cn.yulr.http;

import org.apache._http.HttpException;
import org.apache._http.HttpRequest;
import org.apache._http.nio.protocol.HttpAsyncExchange;
import org.apache._http.nio.protocol.HttpAsyncRequestConsumer;
import org.apache._http.nio.protocol.HttpAsyncRequestHandler;
import org.apache._http.protocol.HttpContext;

import java.io.IOException;

public abstract class MHttpAsyncRequestHandler<T> implements HttpAsyncRequestHandler<T> {

    /**
     * 请求 Action
     * 此部分注册成功之后，无法再次执行修改操作
     */
    protected String requestAction;

    public MHttpAsyncRequestHandler(String requestAction) {
        this.requestAction = requestAction;
    }

    public String getRequestAction() {
        return requestAction;
    }

    @Override
    public abstract HttpAsyncRequestConsumer<T> processRequest(HttpRequest request, HttpContext context) throws HttpException, IOException;

    @Override
    public abstract void handle(T data, HttpAsyncExchange httpExchange, HttpContext context) throws HttpException, IOException;

}
